package cn.yr.controller.manage;

import cn.yr.common.util.AjaxResult;
import cn.yr.domain.entity.SysDictData;
import cn.yr.domain.page.TableDataInfo;
import cn.yr.service.manage.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数据字典信息
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/system/dict/data")
public class SysDictDataController extends BaseController {
	@Autowired
	private ISysDictDataService dictDataService;

	@GetMapping("/list")
	public TableDataInfo list(SysDictData dictData) {
		startPage();
		List<SysDictData> list = dictDataService.selectDictDataList(dictData);
		return getDataTable(list);
	}


	/**
	 * 查询字典数据详细
	 */
	@GetMapping(value = "/{dictCode}")
	public AjaxResult getInfo(@PathVariable Long dictCode) {
		return AjaxResult.success(dictDataService.selectDictDataById(dictCode));
	}

	/**
	 * 根据字典类型查询字典数据信息
	 */
	@GetMapping(value = "/dictType/{dictType}")
	public AjaxResult dictType(@PathVariable String dictType) {
		return AjaxResult.success(dictDataService.selectDictDataByType(dictType));
	}

	/**
	 * 新增字典类型
	 */
	@PostMapping
	public AjaxResult add(@Validated @RequestBody SysDictData dict) {
		//dict.setCreateBy(SecurityUtils.getUsername());
		return toAjax(dictDataService.insertDictData(dict));
	}

	/**
	 * 修改保存字典类型
	 */
	@PutMapping
	public AjaxResult edit(@Validated @RequestBody SysDictData dict) {
		//dict.setUpdateBy(SecurityUtils.getUsername());
		return toAjax(dictDataService.updateDictData(dict));
	}

	/**
	 * 删除字典类型
	 */
	@DeleteMapping("/{dictCodes}")
	public AjaxResult remove(@PathVariable Long[] dictCodes) {
		return toAjax(dictDataService.deleteDictDataByIds(dictCodes));
	}
}
